#include "ceguiresourcemanager.h"
#include "archivemanager.h"

#ifdef _DEBUG
#ifdef _MSC_VER
   #define new   new( _CLIENT_BLOCK, __FILE__, __LINE__)
#endif
#endif // _DEBUG

namespace Engine
{
	/**********************************************************************************************************/
	void CEGUIResourceManager::loadRawDataContainer(const CEGUI::String& filename, CEGUI::RawDataContainer& output, const CEGUI::String& )
	{

		RefPtr<DataStream> file = ArchiveManager::GetSingleton().ReadFile(filename.c_str());
		if(file.IsNull())
			throw std::logic_error("Can't open file " + std::string(filename.c_str()) + "Render::loadRawDataContainer." );


		const size_t memBuffSize = file->GetSize();

		unsigned char* mem = new unsigned char[memBuffSize];
		file->Read(mem, memBuffSize);

		output.setData(mem);
		output.setSize(memBuffSize);
	}
	/**********************************************************************************************************/
	void CEGUIResourceManager::unloadRawDataContainer(CEGUI::RawDataContainer& output)
	{
		if (output.getDataPtr())
		{
			delete[] output.getDataPtr();
			output.setData(0);
			output.setSize(0);
		}
	}
	/**********************************************************************************************************/
}
